<template>
    <div>
        <!-- 面包屑导航 -->
        <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/home/welcome' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>订单管理</el-breadcrumb-item>
            <el-breadcrumb-item>订单列表</el-breadcrumb-item>
        </el-breadcrumb>
        <!-- 卡片 -->
        <el-card class="box-card">
            <el-row :gutter="20">
                <el-col :span="7">
                    <el-input placeholder="请输入内容" v-model="queryInfo.query" clearable @clear="getorderList" >
                        <el-button @click="getorderList" slot="append" icon="el-icon-search"></el-button>
                    </el-input>
                </el-col>
            </el-row>

            <el-table :data="getorderlist" border stripe style="width:100%">
                 <el-table-column align="center" type="index" label="#" ></el-table-column>
                <el-table-column header-align="center" prop="order_number" label="订单编号" width=""></el-table-column>
                <el-table-column align="center" prop="order_price" label="订单价格(元)" width="100px"></el-table-column>

                <el-table-column align="center" prop="order_pay" label="是否付款" width="100px">
                        <template slot-scope="scope">
                                <el-tag type="success" v-if="scope.row.order_pay==1" >已付款</el-tag>
                                <el-tag type="danger" v-else>未付款</el-tag>
                        </template>
                </el-table-column>
                <el-table-column align="center" prop="is_send" label="是否下单" width="100px">
                        
                </el-table-column>
                <el-table-column align="center" prop="create_time" label="下单时间" width="200px">
                    <template slot-scope="scope">{{scope.row.create_time | dataFormat }}</template>
                </el-table-column>
                <el-table-column prop="" label="操作" width="200px">
                    <template slot-scope="scope">
                        <!-- 修改按钮 -->
                        <el-button @click="showeditdialog(scope.row.order_id)" type="primary" size="mini" icon="el-icon-edit"></el-button>
                        <!-- 查看按钮 -->
                        <el-button @click="showProgressDialog()" type="success" size="mini" icon="el-icon-location"></el-button>
                    </template>
                </el-table-column>
            </el-table>

            <!-- 分页 -->
            <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="queryInfo.pagenum"
                :page-sizes="[10, 20, 50, 100]"
                :page-size="queryInfo.pagesize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total">
            </el-pagination>
        </el-card>

        <el-dialog title="修改地址" :visible.sync="addrdialogVisible" width="50%" @close="addrhandleClose">
            <el-form :model="addressForm" :rules="addressFormrules" ref="addressFormruleForm" label-width="100px">
                <el-form-item label="省市区/县" prop="address1">
                    <el-cascader
                        v-model="addressForm.address1"
                        :options="cityData"
                        :props="{ expandTrigger: 'hover' }"
                    ></el-cascader>
                </el-form-item>
                <el-form-item label="详细地址" prop="address2">
                    <el-input v-model="addressForm.address2"></el-input>
                </el-form-item>
            </el-form>

        <span slot="footer" class="dialog-footer">
            <el-button @click="addrdialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="adddrialogVisible = false">确 定</el-button>
        </span>
        </el-dialog>

        <el-dialog title="查看物流" :visible.sync="ProgressdialogVisible" width="50%" @close="ProgresshandleClose">
            <!-- <el-timeline>
                <el-timeline-item
                v-for="(activity, index) in progressInfo"
                :key="index"
                :timestamp="activity.time"
                >{{activity.context}}</el-timeline-item>
            </el-timeline> -->

        </el-dialog>
    </div>
</template>

<script>
import cityData from './citydata.js'
export default {
    data() {
        return {
            queryInfo:{
                query:'',
                pagenum:1,
                pagesize:10
            },
            //订单列表
            getorderlist:[],
            progressInfo:[],
            //列表总数
            total:0,
            //修改地址
            addrdialogVisible:false,
            //查看物流
            ProgressdialogVisible:false,
            addressForm:{
                address1:'',
                address2:''
            },
            addressFormrules:{
                address1: [
                { required: true, message: '请选择省市区县', trigger: 'blur' }
                ],
                address2: [
                { required: true, message: '请输入详细地址', trigger: 'blur' }
                ]
            },
            cityData
        }
    },
    created(){
        this.getorderList()
    },
    methods:{
        async getorderList(){
            const {data:res}=await this.$http.get('orders',{
                params:{
                    query:this.queryInfo.query,
                    pagenum:this.queryInfo.pagenum,
                    pagesize:this.queryInfo.pagesize
                }
            })
            if(res.meta.status!==200){
                return this.$message.error("获取订单列表失败")
            }
            this.$message.success("获取订单列表成功")
            this.getorderlist=res.data.goods
            this.total=res.data.total
        },
        //监听 pagsiz 改变事件
        handleSizeChange(newsizi){
            
            this.queryInfo.pagesize=newsizi;
            this.getorderList();
        },
        //监听 页码 改变事件
        handleCurrentChange(newpage){
            this.queryInfo.pagenum=newpage;
            this.getorderList();
        },
        //修改
        showeditdialog(id){
            this.addrdialogVisible=true
        },
        //关闭
        addrhandleClose(){
            this.$refs.addressFormruleForm.resetFields();
        },
        //查看地址
        async showProgressDialog(){
            // 供测试的物流单号：1106975712662
            const { data: res } = await this.$http.get('/kuaidi/1106975712662')
            if (res.meta.status !== 200) {
                return this.$message.error('获取物流进度失败!')
            }
            this.progressInfo = res.data
            this.progressDialogVisible = true
        },

        ProgresshandleClose(){
            this.ProgressdialogVisible=false
        }

    }
}
</script>

<style lang="less" scope>
    
</style>